package br.com.pmz.gerador.vo.gerados; 

import java.util.Date; 
import java.io.InputStream;

import java.io.Serializable;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;

import javax.persistence.CascadeType;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.JoinColumns;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import java.util.Collection;

<#if table.idClass != "">
import javax.persistence.IdClass;
</#if>
import java.util.Date;

/**
 *
 * Classe referente a tabela ${table.nameDataBase}.
 *
 */
@Entity
<#if table.idClass != "">
@IdClass(${table.idClass}.class)
</#if>
@Table(name = "${table.nameDataBase}")
public final class ${"${table.nameJava}"?cap_first}VO
  implements Serializable {
<#list table.campos as campo>

  /**
   * ${campo.nameDataBase}.
   */
  <#if campo.primaryKey>
  @Id
  </#if>
  @Column(name = "${campo.nameDataBase}",
          length = ${campo.sizeDataBase?string("#")}<#if (campo.precisionDataBase > 0)>,
          precision = ${campo.precisionDataBase}</#if>
          )
  private ${campo.typeJava} ${campo.nameJava};
</#list>
<#list table.fks as fk>
<#if (fk.typeJava?? && fk.nameJava??)>

  /**
   * ${fk.nameFK}.
   */
  @ManyToOne(cascade = { CascadeType.PERSIST, CascadeType.MERGE })
  <#if (fk.join?? && fk.join?size > 1)>
  @JoinColumns(value = {
  <#list fk.join as join>
  		@JoinColumn(name = "${join.fk}", referencedColumnName = "${join.table}", insertable = false, updatable = false)<#if (fk.join?size > 0 && fk.join?last != join)>, </#if>
  </#list>})
  </#if>
  <#if (fk.join?? && fk.join?size == 1)>
  <#list fk.join as join>
  @JoinColumn(name = "${join.fk}", referencedColumnName = "${join.table}", insertable = false, updatable = false)
  </#list>
  </#if>  
  private ${"${fk.typeJava}"?cap_first}VO ${fk.nameJava};
  </#if>
</#list>
<#list table.exported as expo>
<#if (expo.typeJava?? && expo.nameJava??)>

  /**
   * ${expo.nameFK}.
   */
  @OneToMany(mappedBy = "${expo.nameJava}")
  private Collection < ${"${expo.typeJava}"?cap_first}VO > list${"${expo.nameJava}"?cap_first};
</#if>
</#list>
<#list table.campos as campo>

  /**
   *
   * @param param Refere-se ao atributo ${campo.nameJava}
   */
  public void set${"${campo.nameJava}"?cap_first}(final ${campo.typeJava} param) {
    this.${campo.nameJava} = param;
  }

  /**
   *
   * @return Retorna o atributo ${campo.nameDataBase}
   */
  public ${campo.typeJava} get${"${campo.nameJava}"?cap_first}() {
    return this.${campo.nameJava};
  }
</#list>

<#list table.fks as fk>
<#if (fk.typeJava?? && fk.nameJava??)>

  /**
   * @param param Refere-se ao atributo ${fk.nameFK}
   */
  public void set${"${fk.nameJava}"?cap_first}(final ${"${fk.typeJava}"?cap_first}VO param) {
    this.${fk.nameJava} = param;
  }

  /**
   * @return Retorna o atributo ${fk.nameFK}
   */
  public ${"${fk.typeJava}"?cap_first}VO get${"${fk.nameJava}"?cap_first}() {
    return this.${fk.nameJava};
  }
</#if>
</#list>
<#list table.exported as expo>
<#if (expo.typeJava?? && expo.nameJava??)>

  /**
   * @param param Refere-se ao atributo ${expo.nameFK}
   */
  public void setList${"${expo.nameJava}"?cap_first}(final Collection < ${"${expo.typeJava}"?cap_first}VO > param) {
    this.list${"${expo.nameJava}"?cap_first} = param;
  }

  /**
   * @return Retorna o atributo ${expo.nameFK}
   */
  public Collection < ${"${expo.typeJava}"?cap_first}VO > getList${"${expo.nameJava}"?cap_first}() {
    return this.list${"${expo.nameJava}"?cap_first};
  }
</#if>
</#list>
}
